Skip to content

fix(codegen): store a reordered record literal by the expected layout (#817) - #821

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/817-record-field-order
Nov 27, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
fix/817-record-field-order

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Closes #817

Summary

Core WASM stored a record literal in its source field order, but reads used the declared type's layout or the first literal's layout. Both repros in #817 returned the wrong field.

Now, when the expected layout is known, gen_record (lib/codegen.ml) stores each field at that layout's offset. Field values still run in source order. The layout comes from:

  • a let type annotation (let x: Config = #{height: 9, width: 2});
  • the variable's layout, for a local reassignment (r = #{right: 7, left: 3});
  • the callee's parameter type, for a literal passed as an argument (h(#{height: 9, width: 2}));
  • the fn return type, for a tail literal and return #{..}.

Limits

Tests

  • New harness tests/codegen/test_record_field_order.mjs: both repros, direct argument, tail return, early return, and the same-order case. It fails on main (first assert) and passes here.
  • Suites: e2e 657, WASM 48, Bun-ESM 41, native Bun 8. All pass.

Generated by Claude Code

@gitnotebooks

gitnotebooks Bot commented Nov 27, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 55605607-0270-4738-8795-925767e69165
Commits

Reviewing files that changed from the base of the PR and between 0f45cd3 and f9cbe89.

Files selected for processing: 3

  • lib/codegen.ml
  • tests/codegen/record_field_order.affine
  • tests/codegen/test_record_field_order.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 27, 2026 01:07
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-27T01:07:39.540736Z
We couldn’t complete this review. Comment @codex review to try again.
6d0cd7a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…#817)

Core WASM stored a record literal in its source field order, but reads
used the declared type's layout or the first literal's layout. Two
cases returned the wrong field.

When the expected layout is known, each field is now stored at that
offset. Field values still run in source order. The layout comes from:
- a `let` type annotation;
- the variable's layout, for a local reassignment;
- the callee's parameter type, for a literal passed as an argument;
- the fn return type, for a tail literal and `return #{..}`.

Closes #817

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZjyGGiPhiEUxNGPwsr
@hyperpolymath
hyperpolymath force-pushed the fix/817-record-field-order branch from 6d0cd7a to f9cbe89 Compare November 27, 2026 01:38
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit bb595b9 into main Nov 27, 2026
18 checks passed
@hyperpolymath
hyperpolymath deleted the fix/817-record-field-order branch November 27, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: record literal in a non-declared field order reads the wrong field (local reassign, typed let passed to fn)

3 participants